package com.example.mylibrary;

import android.annotation.SuppressLint;
import android.content.Context;
import android.util.AttributeSet;
import android.util.TypedValue;
import android.view.Gravity;
import android.view.ViewGroup;
import android.widget.LinearLayout;
import android.widget.TextView;

import androidx.annotation.Nullable;
import androidx.core.content.res.ResourcesCompat;

import java.time.LocalDate;
import java.util.Calendar;

public class MyCalender extends LinearLayout {
    @SuppressLint("UseCompatLoadingForDrawables")
    public MyCalender(Context context, @Nullable AttributeSet attrs) {
        super(context, attrs);
        setOrientation(LinearLayout.VERTICAL);
        LinearLayout topLayout = new LinearLayout(context);
        LinearLayout bottomLayout = new LinearLayout(context);
        LayoutParams topLP = new LayoutParams(ViewGroup.LayoutParams.MATCH_PARENT,ViewGroup.LayoutParams.WRAP_CONTENT);
        topLP.weight=2;
        topLayout.setBackground(ResourcesCompat.getDrawable(getResources(),R.drawable.top_style,null));
        LayoutParams bottomLP = new LayoutParams(ViewGroup.LayoutParams.MATCH_PARENT,ViewGroup.LayoutParams.WRAP_CONTENT);
        bottomLP.weight=5;
        bottomLayout.setBackground(ResourcesCompat.getDrawable(getResources(),R.drawable.bottom_style,null));
        Calendar calendar = Calendar.getInstance();
        LocalDate now = LocalDate.now();
        String month= calendar.get(Calendar.MONTH)+1+"月";
        String day=String.valueOf(now.getDayOfMonth());
        TextView textMonth = new TextView(context);
        textMonth.setText(month);
        textMonth.setTextSize(TypedValue.COMPLEX_UNIT_SP,20);
        textMonth.setTextColor(0xffffffff);
        TextView textDay = new TextView(context);
        textDay.setText(day);
        textDay.setTextSize(TypedValue.COMPLEX_UNIT_SP,48);
        textDay.setTextColor(0xff000000);
        topLayout.setGravity(Gravity.CENTER);
        bottomLayout.setGravity(Gravity.CENTER);
        topLayout.addView(textMonth);
        bottomLayout.addView(textDay);
        addView(topLayout,topLP);
        addView(bottomLayout,bottomLP);
    }
}
